package generators;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Generator
{
//	protected void generate(Object obj)
//	{
//		
//	}
	
	protected static String eleminateSpaces(String str)
	{
		return str.replace(" ", "");
	}
	
	protected static String toFirstUpperCase(String str)
	{
		return str.replaceFirst(str.substring(0,1), str.substring(0,1).toUpperCase());
	}

	protected static String toFirstLowerCase(String str)
	{
		return str.replaceFirst(str.substring(0,1), str.substring(0,1).toLowerCase());
	}
	
	protected static void writeToFile(String fileName, String str)
	{
		PrintWriter out;
		//
		try {
			out = new PrintWriter(new FileWriter(fileName), true);
			//==========================================================
			out.println(str);
			//==========================================================
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	protected static String readFromFile(String fileName) {
		String str = "";
		String line;
		String lineSeparator = System.getProperty("line.separator");
		// ===============================================
		BufferedReader in = null;
		try {
			in = new BufferedReader(new FileReader(fileName));
			while ((line = in.readLine()) != null) {
				str += line + lineSeparator;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// ===============================================
		return str;
	}
	
	
	protected static String createGeneratorTemplate(String str)
	{
		String line = "";
		String[] all = str.split("\n");
		//========================
		for (int i = 0; i < all.length; i++) {
			all[i] = all[i].replace("\r", "");
			all[i] = all[i].replace("\\", "\\\\");
			all[i] = all[i].replace("\"", "\\\"");
			line += "result += (\"" + all[i] + "\\n\");\n";
		}
		//========================
		return line;
	}

}
